﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SuperFox.SuperServiceReference;

namespace SuperFox
{
    public partial class ShareTheLove : UserControl
    {

        private SuperServiceClient client;

        public ShareTheLove()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
            
            // connect the service

            bool ok = true;

            if(!NameTb.Validate())
                ok = false;

            if(!EmailTb.Validate())
                ok = false;

            if(!FNameTb.Validate())
                ok = false;

            if(!FEmailTb.Validate())
                ok = false;

            if (!ok)
            {
                MessageBox.Show("Please fill in the required fileds");
                return;
            }


            client = ServiceConfig.Connect();
            client.ShareTheLoveCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(client_ShareTheLoveCompleted);
            client.ShareTheLoveAsync(NameTb.Text, EmailTb.Text, FNameTb.Text, FEmailTb.Text, PMTb.Text);

            
        }

        void client_ShareTheLoveCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                this.LayoutRoot.Children.Clear();
                this.LayoutRoot.Children.Add(
                    new TextBlock()
                    { 
                        Text = "Message Sent",
                        Margin = new Thickness(20),
                        Foreground = new SolidColorBrush(Color.FromArgb(255,255,255,255))
                    }
                    );
                
            }
            else
            {
                this.LayoutRoot.Children.Clear();
                this.LayoutRoot.Children.Add(
                    new TextBlock()
                    { 
                        Text = "ERROR sending message",
                        Margin = new Thickness(20),
                        Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255))
                    }
                    );

            }
        }
    }
}
